﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace Red.Controls.ViewModels
{
    /// <summary>
    /// Item that is presented in CommandPalette listbox.
    /// </summary>
    public class CommandPaletteItem
    {
        #region Data

        private int _iconSize = 16;

        #endregion Data

        #region Properties

        /// <summary>
        /// Name of the item that is displayed in command palette listbox.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Comment that is displayed in command palette tooltip.
        /// </summary>
        public string Comment { get; set; }

        /// <summary>
        /// Optional icon to display to the left of the item name (May be null)
        /// </summary>
        public Canvas IconCanvas { get; set; }

        /// <summary>
        /// Square size the icon will be displayed at (if there is an icon to display)
        /// </summary>
        /// <remarks>
        /// Not an auto property so that a sensible default value can be assigned
        /// </remarks>
        public int IconSize { get { return _iconSize; } set { _iconSize = value; } }

        #endregion Properties

        #region Events

        /// <summary>
        /// Click event that is raised after choosing command palette item. 
        /// This item passes itself as an event sender.
        /// </summary>
        public EventHandler Click { get; set; }
        internal virtual void RaiseClick()
        {
            if ( Click != null )
                Click( this, EventArgs.Empty );
        }

        #endregion Events
    }

    /// <summary>
    /// CommandPaletteItem which can hold additional data.
    /// </summary>
    /// <typeparam name="DataType">Type of additional data which is passed as an event argument to Click event handler.</typeparam>
    public class CommandPaletteItem<DataType> : CommandPaletteItem
    {
        #region Data

        /// <summary>
        /// Additional data that we want to pass within command palette item.
        /// </summary>
        private DataType _Data;

        #endregion Data

        #region Events

        public new EventHandler<DataType> Click { get; set; }
        internal override void RaiseClick()
        {
            if ( Click != null )
                Click( this, _Data );
        }

        #endregion Events

        #region C-tor

        public CommandPaletteItem( DataType data )
        {
            _Data = data;
        }

        #endregion C-tor
    }
}
